Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x] Add success and failure command assertions #39435

Merged
merged 4 commits into from
Nov 2, 2021

Conversation

roberto-aguilar
Copy link
Contributor

@roberto-aguilar roberto-aguilar commented Nov 1, 2021

After browsing some of my tests for the console commands, I found that I have been doing either:

$this->artisan(FooCommand::class)->assertExitCode(0);
$this->artisan(FooCommand::class)->assertExitCode(1);

or

$this->artisan(FooCommand::class)->assertExitCode(Command::SUCCESS);
$this->artisan(FooCommand::class)->assertExitCode(Command::FAILURE);

With this new set of assertions, this can be unified and by having the IDE to provide auto-completion, writing tests feels smoother:

$this->artisan(FooCommand::class)->assertSuccessful();
$this->artisan(FooCommand::class)->assertFailed();

@roberto-aguilar roberto-aguilar changed the title Add success and failure command assertions [8.x] - Add success and failure command assertions Nov 1, 2021
@taylorotwell
Copy link
Member

What about just assertSuccessful and assertFailed?

@roberto-aguilar
Copy link
Contributor Author

Sounds great, I just renamed the methods.

Thanks for the feedback, @taylorotwell!

*
* @return $this
*/
public function assertFailed()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonder if this should assert exit code not equal to zero. Commands can fail with exit codes other than 1.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're totally right, @GrahamCampbell, I updated the implementation based on this 👍

@roberto-aguilar
Copy link
Contributor Author

roberto-aguilar commented Nov 1, 2021

The test failures seem unrelated to this PR, but please let me know if I can do anything for them 😃

@GrahamCampbell GrahamCampbell changed the title [8.x] - Add success and failure command assertions [8.x] Add success and failure command assertions Nov 1, 2021
@taylorotwell taylorotwell merged commit b3705b9 into laravel:8.x Nov 2, 2021
@roberto-aguilar roberto-aguilar deleted the command-assertions branch November 2, 2021 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants